from IPython.display import Audio, display, HTML
import librosa
import matplotlib.pyplot as plt
import numpy as np
import os
!scp -i ~/.ssh/no_passphrase_rsa peterpaullake@35.247.96.44:/home/peterpaullake/wn/voice-and-music.wav voice-and-music/
!scp -i ~/.ssh/no_passphrase_rsa peterpaullake@35.247.96.44:/home/peterpaullake/wn/*.npy voice-and-music/
voice-and-music.wav 100% 108KB 327.4KB/s 00:00 mel-00000-mixed.npy 100% 135KB 428.1KB/s 00:00 mel-00000.npy 100% 135KB 855.1KB/s 00:00 mel-00001-mixed.npy 100% 136KB 1.6MB/s 00:00 mel-00001.npy 100% 136KB 1.6MB/s 00:00 mel-00002-mixed.npy 100% 136KB 1.7MB/s 00:00 mel-00002.npy 100% 136KB 1.6MB/s 00:00 mel-00003-mixed.npy 100% 137KB 1.6MB/s 00:00 mel-00003.npy 100% 137KB 1.6MB/s 00:00 mel-00004-mixed.npy 100% 138KB 1.6MB/s 00:00 mel-00004.npy 100% 138KB 1.6MB/s 00:00 mel-00005-mixed.npy 100% 138KB 1.7MB/s 00:00 mel-00005.npy 100% 138KB 1.6MB/s 00:00 mel-00006-mixed.npy 100% 139KB 1.6MB/s 00:00 mel-00006.npy 100% 139KB 1.7MB/s 00:00 mel-00007-mixed.npy 100% 140KB 1.6MB/s 00:00 mel-00007.npy 100% 140KB 1.6MB/s 00:00 mel-00008-mixed.npy 100% 140KB 1.6MB/s 00:00 mel-00008.npy 100% 140KB 1.7MB/s 00:00 mel-00009-mixed.npy 100% 141KB 1.7MB/s 00:00 mel-00009.npy 100% 141KB 1.7MB/s 00:00 mel-00010-mixed.npy 100% 141KB 1.7MB/s 00:00 mel-00010.npy 100% 141KB 1.7MB/s 00:00 mel-00011-mixed.npy 100% 142KB 1.6MB/s 00:00 mel-00011.npy 100% 142KB 1.6MB/s 00:00 mel-00012-mixed.npy 100% 143KB 1.7MB/s 00:00 mel-00012.npy 100% 143KB 1.7MB/s 00:00 mel-00013-mixed.npy 100% 143KB 1.7MB/s 00:00 mel-00013.npy 100% 143KB 1.7MB/s 00:00 mel-00014-mixed.npy 100% 144KB 1.7MB/s 00:00 mel-00014.npy 100% 144KB 1.7MB/s 00:00 mel-00015-mixed.npy 100% 145KB 1.7MB/s 00:00 mel-00015.npy 100% 145KB 1.6MB/s 00:00 mel-00016-mixed.npy 100% 145KB 1.7MB/s 00:00 mel-00016.npy 100% 145KB 1.8MB/s 00:00 mel-00017-mixed.npy 100% 146KB 1.7MB/s 00:00 mel-00017.npy 100% 146KB 1.7MB/s 00:00 mel-00018-mixed.npy 100% 146KB 1.7MB/s 00:00 mel-00018.npy 100% 146KB 1.8MB/s 00:00 mel-00019-mixed.npy 100% 147KB 1.7MB/s 00:00 mel-00019.npy 100% 147KB 1.5MB/s 00:00 mel-00020-mixed.npy 100% 148KB 1.7MB/s 00:00 mel-00020.npy 100% 148KB 1.7MB/s 00:00 mel-00021-mixed.npy 100% 148KB 1.7MB/s 00:00 mel-00021.npy 100% 148KB 1.8MB/s 00:00 mel-00022-mixed.npy 100% 149KB 1.7MB/s 00:00 mel-00022.npy 100% 149KB 1.8MB/s 00:00 wave-00001.npy 100% 216KB 2.6MB/s 00:00 wave-00002.npy 100% 217KB 2.5MB/s 00:00 wave-00003.npy 100% 218KB 2.6MB/s 00:00 wave-00004.npy 100% 219KB 2.6MB/s 00:00 wave-00005.npy 100% 220KB 2.6MB/s 00:00 wave-00006.npy 100% 221KB 2.6MB/s 00:00 wave-00007.npy 100% 222KB 2.6MB/s 00:00 wave-00008.npy 100% 223KB 2.6MB/s 00:00 wave-00009.npy 100% 224KB 2.7MB/s 00:00 wave-00010.npy 100% 225KB 2.4MB/s 00:00 wave-00011.npy 100% 226KB 2.6MB/s 00:00 wave-00012.npy 100% 227KB 2.7MB/s 00:00 wave-00013.npy 100% 228KB 2.7MB/s 00:00 wave-00014.npy 100% 229KB 2.7MB/s 00:00 wave-00015.npy 100% 230KB 2.7MB/s 00:00 wave-00016.npy 100% 231KB 2.6MB/s 00:00 wave-00017.npy 100% 232KB 2.7MB/s 00:00 wave-00018.npy 100% 233KB 2.7MB/s 00:00 wave-00019.npy 100% 234KB 2.7MB/s 00:00 wave-00020.npy 100% 235KB 2.5MB/s 00:00 wave-00021.npy 100% 236KB 2.5MB/s 00:00 wave-00022.npy 100% 237KB 2.6MB/s 00:00
RATE = 22050
def forever():
"""Generator for iterating over integers from 0 onwards."""
i = 0
while True:
yield i
i += 1
def plot_wave(ax, wave, title='', range=None):
ax.set_title(title)
if range is not None:
ax.plot(wave[range[0]:range[1]])
else:
ax.plot(wave)
def plot_mel(ax, mel, title=''):
ax.set_title(title)
pos = ax.imshow(mel.transpose(), aspect='auto', cmap='coolwarm', interpolation='nearest', origin='lower')
# fig.colorbar(pos, orientation='horizontal')
def show_wave_and_mel(wave, mel, mel_mixed=None, title=''):
n_plots = 2 if mel_mixed is None else 3
fig, axes = plt.subplots(n_plots, dpi=100, figsize=(10, 6))
plot_wave(axes[0], wave, title)
n_zoom = int(0.5 * RATE)
mid = len(wave) // 2
# plot_wave(axes[1], wave, 'Zoomed in', (mid - n_zoom // 2, mid + n_zoom // 2))
plot_mel(axes[1], mel, 'Mel spectrogram')
if n_plots == 3:
plot_mel(axes[2], mel_mixed, r'$0.6 \times$ old mel spectrogram + $0.4 \times$ new mel spectrogram')
plt.subplots_adjust(hspace=0.4)
plt.show()
display(Audio(wave, rate=RATE))
gid = 0
def show_results(name, title):
display(HTML('<h1>%s</h1>' % title))
for i in forever():
try:
if i == 0:
wave = librosa.core.load(os.path.join(name, name + '.wav'))[0]
else:
wave = np.load(os.path.join(name, 'wave-%.5d.npy' % i))
mel = np.load(os.path.join(name, 'mel-%.5d.npy' % i))
except FileNotFoundError:
break
if i == 0:
title = 'Seed audio'
else:
title = ('Audio after %d WaveNet application' + ('' if i == 1 else 's')) % i
if i == 0:
show_wave_and_mel(wave, mel, title=title)
else:
mel_mixed = np.load(os.path.join(name, 'mel-%.5d-mixed.npy' % i))
show_wave_and_mel(wave, mel, mel_mixed, title)
global gid
print('id: %d' % gid)
gid += 1
display(HTML('<hr style="height: 2px;">'))
show_results('voice-and-music', 'Music and speech as seed audio')
id: 0
id: 1
id: 2
id: 3
id: 4
id: 5
id: 6
id: 7
id: 8
id: 9
id: 10
id: 11
id: 12
id: 13
id: 14
id: 15
id: 16
id: 17
id: 18
id: 19
id: 20
id: 21
id: 22